﻿#ifndef __TEST_H__
#define __TEST_H__

#include "cocos2d.h"
#include "Loot.h"
#include "Spell.h"
#include "Unit.h"
#include "Player.h"
#include "Monster.h"
#include "Bag.h"
#include "EquipUI.h"
#include "DataBase.h"
#include "GetString.h"

USING_NS_CC;

#define MAPID_MAX								9999
#define MAX_ITEM_VALUE_COUNT					10
#define MOUSE_SELECTED_NONE						-9999
#define PLAYER_DEAD_TALK_CLASS_TAG				400
#define PLAYER_DEAD_TALK_CLASS_BUTTON_TAG		401
#define END_OF_MAP_LAYER_RIGHT					2580.0f
#define BLACK_BACK_GROUND_TAG					402
#define sWorld									Map_Scene::GetInstance()
#define sConfig									TextLoadMgr::SharedTextLoadMgr()

//屏幕分辨率百分比--以1280为基准
static float UISize;

static CCSize VisableSize;

enum MouseMoveFlag
{
	FLAG_NONE,
	FLAG_CHANGEED,
};
//物品潜能
enum ItemPotential
{
	MAIN_ONE,
	MAIN_TWO,
	MAIN_THREE,
	SUB_ONE,
	SUB_TWO,
	SUB_THREE,
};

enum BondingType
{
	None,
	LootBonding,
	EquipBonding,
	UseBonding,
};
enum Facing
{
	left,
	right
};

enum PlayerValuesViewName
{
	PLAYER_NAME,
	PLAYER_CLASS,
	PLAYER_LEVEL,
	PLAYER_PK,
	PLAYER_FAMLIY,
	PLAYER_HP,
	PLAYER_MP,
	PLAYER_REP,
	PLAYER_POP,
	PLAYER_UNUSED_TALENT,
	PLAYER_STR,
	PLAYER_DEX,
	PLAYER_INT,
	PLAYER_LUK,
	PLAYER_COMBAT_EXP,
	PLAYER_BP,
	PLAYER_ATTACK,
	PLAYER_CIRT_CHANCE,
	PLAYER_ATTACK_DEFANCE,
	PLAYER_MAGIC_ATTACK_DEFANCE,
	PLAYER_ATTACK_HIT_CHANCE,
	PLAYER_MAGIC_HIT_CHANCE,
	PLAYER_ATTACK_MISS_CHANCE,
	PLAYER_MAGIC_ATTACK_MISS_CHANCE,
	PLAYER_MOVE_SPEED,
	PLAYER_JUMP_HIGH,

	PLAYER_VALUE_VIEW_NAME_END,
};
enum ItemSlot
{
	//戒指位置
	RING_ZERO,
	RING_ONE,
	RING_TWO,
	RING_THR,
	RING_FOR,
	RING_FIVE,

	//项链1
	NECKLACE_ZERO,
	//项链2
	NECKLACE_ONE,
	//主手
	MAIN_HAND,
	//腰带
	BELT,
	//头部
	HEAD,
	//脸部
	FACE,
	//眼部
	EYE,
	//上衣
	JACKET,
	//下衣
	PANTS,
	//鞋子
	SHOES,
	//口袋
	PACKET,
	//耳环
	EAR,
	//肩膀
	SHOULDER,
	//手腕
	WRIST,
	//机器人
	ROBOT,
	//能源
	SOURCE,
	//徽章
	DADGE_ZERO,
	//胸章
	DADGE_ONE,
	//副手
	OFF_HAND,
	//背部
	BACK,
	//机器心脏
	ROBOT_HEART,
};

enum ItemValue
{
	Item_Value_None,
	Item_Value_Mana,
	Item_Value_Heath,
	Item_Value_Str,
	Item_Value_Dex,
	Item_Value_Int,
	Item_Value_Luk,
	Item_Value_Att,
	Item_Value_Magic_Att,
	Item_Value_Att_Defance,
	Item_Value_Magic_Defance,
	Item_Value_MissChance,
	Item_Value_JumpHigh,
	Item_Value_MoveSpeed,
	Item_Value_BossDamage,
	Item_Value_Defance_Ingnore,
};

struct ItemTemplateStr
{
	int Entry;
	std::string Name;
	std::string Image_Url;
	int NeedLevel = 0;
	int SellPrice = 0;
	int BuyPrice = 0;
	int Exchange_Cost = 0;
	int Item_Flag = 0;
	ItemSlot Item_Slot;
	ClassID NeedClass;
	BondingType BondingType;
	std::map<ItemValue, int> ItemValues;
};

struct MonsterLootSingleInfo
{
	int MonsterEntry;
	int Item_Entry;
	int Count;
	int MaxCount;
	int Chance;
};

struct MonstersBaseInfo
{
	int Entry;
	int maxheath;
	int Attack_Power;
	int Defance;
	float MissChance;
	float CritChance;
	int Level;
	int Loot;
	int reswardexp;
	int rewardmoney;
	std::string imageurl;
	std::string deadsoundurl;
	std::string takedamagesoundurl;
};

struct MapInfo
{
	int MapID;
	int MonsterEntry;
	int MonsterGuid;
	float PosX;
	float PosY;
};

struct MoveType
{
	bool Left;
	bool Right;
	bool Up;
	bool Down;
	bool Alt;
};

struct LevelInfo
{
	int Level;
	int NeedExp;
};

typedef std::map<Unit*, Spell*> UnitSpellMap;
class PlayerUILayer : public cocos2d::CCLayer
{
public:
	PlayerUILayer();
	~PlayerUILayer();
	CREATE_FUNC(PlayerUILayer);
	virtual bool init();
	virtual void update(float second);
	virtual bool onTouchBegan(Touch *touch, Event *unused_event);
	virtual void onTouchMoved(Touch *touch, Event *unused_event);
	virtual void onTouchEnded(Touch *touch, Event *unused_event);
	virtual void onMouseMove(Event *pevent);
	static PlayerUILayer* GetInstance();

	CCLabelTTF* GetPlayerValuesLable(PlayerValuesViewName _PlayerValuesViewName);
	void AddLootInfoToLayer(std::string Name);
	void SendPlayerNotify(std::string _Notify);
	void CheckCCProgress();
	void ResetLevelString();
	void SetMouseMoveToTag(int _Tag);
	void SetCharacterValueVisable(bool _vis);
	void SetCharacterEquipUIVisable(bool _vis)		{ _EquipUI->setVisible(_vis); }
	bool GetCharacterValueVisable()					{ return CharacterValue_Main_UI_Back->GetVisible(); }
	bool GetCharacterEquipUIVisable()				{ return _EquipUI->GetVisible(); }
	void ReLoadPlayerValueNumber();
private:
	void ReMovePlayerNotify(CCLabelTTF* pLable);
	void RemoveLableFromLootLayer(CCLabelTTF* pLable);
	Slot* GetComeFromSlot();
	bool IsTouchedSprite(Touch* pTouch, CCSprite* pSprite);
	void SetTouchItem(Item* pItem)		{ m_IsTouchWithItem = true; m_TouchedItem = pItem; }
	bool IsTouuchWithItem()			{ return m_IsTouchWithItem; }
	void ReSetItemViewStringForShow(Slot* pSlot, int PlayerUITag = 0);
	void ReSetPlayerItemViewWindowPostion(int NearByUI = 0);
	void SetItemViewVisable(bool _vis);
	void CheckMouseAction();
	std::string itoc(int _int);
	void InitButtonMainUI();
	void InitCharacterValueUI();
	void InitPlayerEquipUI();
	void InitPlayerDeadTalkClass();
	void ReSetMoveInfo();
	bool IsThisUICanMoveByTouch(int TouchedUI);
	void MovingPlayerUIWitchTouch(CCSprite* pSprite, float NeedMoveX, float NeedMoveY);



	CCSprite* _TouchedSprite;
	CCSprite* ButtonMainUI;
	CCSprite* ButtonSkillKeyBoardUI;
	CCSprite* PlayerHpUI;
	CCSprite* PlayerMpUI;
	CCLabelTTF* LevelText;
	CCLabelTTF* NameText;
	CCLabelTTF* ClassText;
	CCProgressTimer* Button_Hp;
	CCProgressTimer* Button_Mp;
	CCProgressTimer* Button_Exp;

	CCSprite* CharacterValue_Main_UI;
	CCSprite* CharacterValue_Main_UI_Back;
	CCSprite* CharacterValue_Detail_UI;
	CCSprite* CharacterValue_Detail_UI_Back;

	EquipUI* _EquipUI;
	CCSprite* PlayerDeadTalkClass;
	CCSprite* PlayerDeadTalkClassButton;

	int TouchedUI;
	float LastTouchX;
	float LastTouchY;
	float TouchMoveX;
	float TouchMoveY;
	float UIMoveX;
	float UIMoveY;
	int m_MouseMoveToTag;
	MouseMoveFlag m_MouseMoveFlag;
	bool m_IsTouchWithItem;
	Item* m_TouchedItem;
	std::map<PlayerValuesViewName, CCLabelTTF*> PlayerValueUILable;
	std::vector<CCLabelTTF*> LootInfo;
	std::vector<CCLabelTTF*> PlayerNotify;
};

class Map_Layer : public cocos2d::CCLayer
{
public:
	Map_Layer();
	~Map_Layer();
	CREATE_FUNC(Map_Layer);

	void SetMapID(int value)		{ m_MapID = value; }
	static Map_Layer* GetInstance();
	virtual bool init();
	virtual void update(float second);
	void CleanUpSpellWhenDelete(Unit* pUnit);
	void AddSpellToMap(Unit*pUnit, Spell* pSpell);
	bool CanMoveFall(CCSprite* Checked);
	bool CanMoveLeft(CCSprite* pChecked);
	bool CanMoveRight(CCSprite* pChecked);
	float GetGroundPointY();
	bool IsInSide(CCSprite* Checked, CCSprite* Checker);
	void AddMonsterToMap();
	void RemoveLoot(Loot* pLoot);
	void AddLoot(Loot* pLoot);
	std::vector<Monster*> GetMonsters()		{ return Monsters; }
	void RemoveMonsterFromMapWhenDead(Monster* pMonster);
	bool IsUnitCastingSpell(Unit* pUnit);
	void RemoveUnitSpellFromMap(Unit* pUnit);
	void ReplaceMapForDeadPlayer();
private:
	Player* player;
	void CreateBlackBackGround();
	void RemoveBlackBackGround();
	void RemoveEveryThing();
	void ReSetAllVectorsAndMaps();
	void CheckLoot();
	void onKeyPressed(EventKeyboard::KeyCode keyCode, Event* event);
	void onKeyReleased(EventKeyboard::KeyCode keyCode, Event* event);
	MoveType _MoveType;
	Facing _Facing;
	float Resettimer;
	void InitMap();
	bool IsBagOpened();
	bool m_IsBagOpened;
	std::vector<CCSprite*>	MapGround;
	std::vector<CCSprite*>	Backs;
	std::vector<CCSprite*>	Threes;
	std::vector<CCSprite*>	Clouds;
	std::vector<Monster*>	Monsters;
	std::vector<Loot*>		Loots;
	UnitSpellMap			Spells;
	int m_MapID;
private:

};



class Map_Scene : public cocos2d::CCScene
{
public:
	Map_Scene();
	~Map_Scene();

	static cocos2d::Scene* createScene();
	static Map_Scene* GetInstance();
	CREATE_FUNC(Map_Scene);
	virtual bool init();
	virtual void update(float diff);
	Player* GetLoadedPlayer()												{ return _player; }
	std::vector<MapInfo> GetMapInfoVector(int mapid)						{ return MapInfoMap[mapid]; }
	std::map<int, MonstersBaseInfo> GetMonsterMap()							{ return MonsterMap; }
	std::vector<LevelInfo> GetLevelInfo()									{ return LevelInfoVector; }
	ItemTemplateStr GetItemTemplate(int _Entry);
	int GetNowMapID();
	std::vector<MonsterLootSingleInfo> GetLootTemplate(int MonesterEntry);



	//Get && Set
	int GetDeadPunish_Money()													{ return DeadPunish_Money; }
	float GetDeadPunish_Exp()													{ return DeadPunish_Exp; }
private:
	void LoadLevelTemplate();
	void LoadEveryThingFromDB();
	void LoadMapMonsterInfo();
	void LoadMapInfo();
	void LoadItemTemplate();
	void LoadLootTemplate();
	void LoadConfDefault();
private:

	int DeadPunish_Money;
	float DeadPunish_Exp;
	Player* _player;
	Map_Layer* _Map_Layer;
	PlayerUILayer* _PlayerUILayer;
	std::map<int, MonstersBaseInfo> MonsterMap;
	std::map<int, std::vector<MapInfo>> MapInfoMap;
	std::vector<MapInfo> MapMonsterVector;
	std::vector<LevelInfo> LevelInfoVector;
	std::map<int, ItemTemplateStr> ItemTemplate;
	std::map<int, std::vector<MonsterLootSingleInfo>> MonsterLootMap;
	int m_NowMapID;
};




#endif